﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

using System.IO;
using H2.NET.Data.Exceller;



namespace H2.NET.Web.Pages
{
    public partial class PHSP : TaskPage
    {
        #region 属性 Public

        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }

        public string Key
        {
            get
            {
                return ViewState["Key"] == null ? "" : (string)ViewState["Key"];

            }
            set { ViewState["Key"] = value; }
        }

       
        #endregion

        #region 事件 Page_Load(页面加载)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;

                //InitDropDownList();
                
                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    VD.Checked = true;
 
                }
                #endregion

                #region 审批环节
                else
                {
                    #region 加载数据并显示
                    hsp_SpecialPrice hsp = (hsp_SpecialPrice.process == TaskAPI.Process & hsp_SpecialPrice.incident == TaskAPI.Incident).ListFirst<hsp_SpecialPrice>();
                    if (hsp != null)
                    {
                        ApplicationNo.Text                  = hsp.ApplicationNo;
                        VD.Checked                          = hsp.VD_Checked == "1";
                        SA.Checked                          = hsp.SA_Checked == "1";
                        SA2.Checked                         = hsp.SA2_Checked == "1";
                        VD_Category.SelectedValue           = hsp.VD_Category;
                        DrpPriority.SelectedValue = hsp.DrpPriority;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            SpecialA_Condition_Type.Text = hsp.SpecialA_Condition_Type;
                            SpecialA_Sorg_DC.Checked = hsp.SpecialA_Sorg_DC == "1";
                            SpecialA_Sales_Organization.Text = hsp.SpecialA_Sales_Organization;
                            Distribution_Channel.Text = hsp.Distribution_Channel;
                        }
                        SpecialA_Division.SelectedValue     = hsp.SpecialA_Division;
                        SpecialA_Sold.Text                  = hsp.SpecialA_Sold;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            SpecialB_Condition_Type.Text = hsp.SpecialB_Condition_Type;
                            SpecialB_Sorg_DC.Checked = hsp.SpecialB_Sorg_DC == "1";
                            SpecialB_Sales_Organization.Text = hsp.SpecialB_Sales_Organization;
                            SpecialB_Channel.Text = hsp.SpecialB_Channel;
                        }
                        SpecialB_Division.SelectedValue     = hsp.SpecialB_Division;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            SpecialC_Condition_Type.Text = hsp.SpecialC_Condition_Type;
                            SpecialC_Sorg_DC.Checked = hsp.SpecialC_Sorg_DC == "1";
                            SpecialC_Sales_Organization.Text = hsp.SpecialC_Sales_Organization;
                            SpecialC_Channel.Text = hsp.SpecialC_Channel;
                        }
                        SpecialC_Division.SelectedValue     = hsp.SpecialC_Division;
                        SpecialC_Customer.Text              = hsp.SpecialC_Customer;

                        DMO_DrpPriority.SelectedValue = hsp.DMO_DrpPriority;
                    }
                    #endregion

                    #region 审批项初始化
                    switch (TaskAPI.Step)
                    {
                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                            Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;
                    

                    }
                    #endregion
                }
                #endregion

                #region 设置控件禁启用
                bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                SetEnable(flg, VD, SA, SA2, VD_Category,DrpPriority, SpecialA_Division, SpecialA_Sold, SpecialB_Division, SpecialC_Division, SpecialC_Customer);
                SetVisible(flg, Special_C_Add, Special_C_Delete, Special_B_Add, Special_A_Add, Special_B_Delete,Special_A_Delete);
                SetEnable(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", DMO_DrpPriority);
                SetVisible(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", P_DMO);
                //SetEnable(TaskAPI.Step == "DMO Maintain", SAP_Code);
                Assessment1.Enable = TaskAPI.IsAllowSubmit;
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);

                
                Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                InitTabs();
                #endregion

                #region 加深颜色
                string item = null;
                string value = null;
                foreach (Control cr in this.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            item = tb.SelectedItem.Text;
                            value = tb.SelectedValue.ToString();
                            tb.Items.Clear();
                            tb.Items.Add(new ListItem(item, value));
                        }
                        tb.ForeColor = System.Drawing.Color.DimGray;
                    }
                }
                if (!flg || !TaskAPI.IsAllowSubmit)
                {

                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                }

                #endregion
            }
        }


        protected override void OnLoad(EventArgs e)
        {
            InitControls();
            base.OnLoad(e);
        }

        public void InitControls()
        {
            bool flg = TaskAPI.IsAllowSubmit && TaskAPI.IsBeginStep;

            gv_Special_A.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("01", "Material", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialA_Material", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("02", "Status", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialA_Status", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("03", "Description", BoundColumnType2.TextBox, 100, Align.Left, flg, "SpecialA_Description", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("04", "Proc.Stat", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialA_Proc", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("05", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialA_Amount", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("06", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialA_Unit", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("07", "Per", BoundColumnType2.TextBox, 60, Align.Left, false, "SpecialA_Per", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("08", "UoM", BoundColumnType2.TextBox, 60, Align.Left, false, "SpecialA_Uom", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("09", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialA_Calculat_Type", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("10", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialA_ScaleBasis", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("11", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialA_Valid_From", InputType.None, null));
            gv_Special_A.DynamicColumn.Add(new BoundColumn2("12", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialA_Valid_To", InputType.None, null));

           
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("01", "Material", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialB_Material", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("02", "Description", BoundColumnType2.TextBox, 100, Align.Left, flg, "SpecialB_Description", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("03", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialB_Amount", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("04", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialB_Unit", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("05", "Per", BoundColumnType2.TextBox, 60, Align.Left, false, "SpecialB_Per", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("06", "UoM", BoundColumnType2.TextBox, 60, Align.Left, false, "SpecialB_Uom", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("07", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialB_Calculat_Type", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("08", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialB_ScaleBasis", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("09", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialB_Valid_From", InputType.None, null));
            gv_Special_B.DynamicColumn.Add(new BoundColumn2("10", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialB_Valid_To", InputType.None, null));

            gv_Special_C.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("01", "Group", BoundColumnType2.TextBox, 100, Align.Left, flg, "SpecialC_Group", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("02", "Subgroup", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialC_Subgroup", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("03", "PH4", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialC_PH4", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("04", "Tin size", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialC_Tin", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("05", "Description", BoundColumnType2.TextBox, 100, Align.Left, flg, "SpecialC_Description", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("06", "Amount", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialC_Amount", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("07", "Unit", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialC_Unit", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("08", "Per", BoundColumnType2.TextBox, 60, Align.Left, false, "SpecialC_Per", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("09", "UoM", BoundColumnType2.TextBox, 60, Align.Left, false, "SpecialC_Uom", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("10", "Calculat.type", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialC_Calculat_Type", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("11", "ScaleBasis", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialC_ScaleBasis", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("12", "Valid From", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialC_Valid_From", InputType.None, null));
            gv_Special_C.DynamicColumn.Add(new BoundColumn2("13", "Valid To", BoundColumnType2.TextBox, 60, Align.Left, flg, "SpecialC_Valid_To", InputType.None, null));

                      
            
            
            
            
            if (!Page.IsPostBack)
            {
                gv_Special_A.Key = Key;
                gv_Special_B.Key = Key;
                gv_Special_C.Key = Key;


              

                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    List<hsp_SpecialPriceA_Gridview> sp1_s = new List<hsp_SpecialPriceA_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp1_s.Add(new hsp_SpecialPriceA_Gridview());
                        sp1_s[i].No = i + 1;
                    }
                    gv_Special_A.DataSource = sp1_s;

                    List<hsp_SpecialPriceB_Gridview> sp2_s = new List<hsp_SpecialPriceB_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp2_s.Add(new hsp_SpecialPriceB_Gridview());
                        sp2_s[i].No = i + 1;
                    }
                    gv_Special_B.DataSource = sp2_s;

                    List<hsp_SpecialPriceC_Gridview> sp3_s = new List<hsp_SpecialPriceC_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sp3_s.Add(new hsp_SpecialPriceC_Gridview());
                        sp3_s[i].No = i + 1;
                    }
                    gv_Special_C.DataSource = sp3_s;

                  
                }
                #endregion

                #region 审批环节
                else
                {
                    IList<hsp_SpecialPriceA_Gridview> sp1_s = (hsp_SpecialPriceA_Gridview.process == TaskAPI.Process & hsp_SpecialPriceA_Gridview.incident == TaskAPI.Incident).List<hsp_SpecialPriceA_Gridview>();
                    if (sp1_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp1_s.Add(new hsp_SpecialPriceA_Gridview());
                            sp1_s[i].No = i + 1;
                        }
                    }
                    gv_Special_A.DataSource = sp1_s;
                    


                    IList<hsp_SpecialPriceB_Gridview> sp2_s = (hsp_SpecialPriceB_Gridview.process == TaskAPI.Process & hsp_SpecialPriceB_Gridview.incident == TaskAPI.Incident).List<hsp_SpecialPriceB_Gridview>();
                    if (sp2_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp2_s.Add(new hsp_SpecialPriceB_Gridview());
                            sp2_s[i].No = i + 1;
                        }
                    }
                    gv_Special_B.DataSource = sp2_s;

                    IList<hsp_SpecialPriceC_Gridview> sp3_s = (hsp_SpecialPriceC_Gridview.process == TaskAPI.Process & hsp_SpecialPriceC_Gridview.incident == TaskAPI.Incident).List<hsp_SpecialPriceC_Gridview>();
                    if (sp3_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sp3_s.Add(new hsp_SpecialPriceC_Gridview());
                            sp3_s[i].No = i + 1;
                        }
                    }
                    gv_Special_C.DataSource = sp3_s;

                }
                #endregion
            }
            //SetVisible(flg, SEFI_1_Add, SEFI_2_Add);
        }
        #endregion  
        
        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Check" || TaskAPI.Step == "DMO Approve") && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        ApplicationNo.Text        = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName          = UserAPI.UserName;
                        TaskAPI["ApplicationNo"]  = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"]     = UserAPI.UserName;
                        TaskAPI["Time"]           = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"]     = UserAPI.Department;
                        TaskAPI["ServerName"] = Util.AppSettings("ServerName");
                    }
                    
                    TaskAPI.Summary = (VD_Category.SelectedItem.Text.Split(',').Length >= 2 ? VD_Category.SelectedItem.Text.Split(',')[1].Trim() : VD_Category.Text)
                                    + " / " + ApplicationNo.Text + (VD.Checked ? " / Special Price A " : "") + (SA.Checked ? " / Special Price B  " : "") + (SA2.Checked ? " / Special Price C  " : "");

                    TaskAPI["Actions"]        = VD_Category.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                    TaskAPI["DrpPriority"] = DrpPriority.SelectedItem.Text;

                    #region 从数据库取得流程步骤处理人
                    SortedList<string, string> rec_a = new SortedList<string, string>();

                    IList<mdc_Recipient> rec_s = (mdc_Recipient.process == TaskAPI.Process & (mdc_Recipient.distribute == VD_Category.SelectedValue | mdc_Recipient.distribute == "*") & mdc_Recipient.status == 1).List<mdc_Recipient>();
                    foreach (mdc_Recipient rec in rec_s)
                    {
                        if (!rec_a.ContainsKey(rec.Step))
                        {
                            rec_a.Add(rec.Step, rec.Recipient);
                            continue;
                        }

                        if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                        {
                            continue;
                        }

                        rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                    }

                    //步骤处理人赋值
                    for (int i = 0; i < rec_a.Keys.Count; i++)
                    {
                        TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    }

                    m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.supervisorEmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                    if (oc != null)
                    {
                        TaskAPI["R_Marketing_Manager"] = oc.WinID;
                    }

                   

                    #endregion
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"]        = TaskAPI.TaskID;
                }

               

                //#region 退回步骤并返回功能 传值
                //if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                //{
                //    TaskAPI["Step"] = Assessment1.JumpStep;
                //    TaskAPI["PreStep"] = TaskAPI.Step;
                //}
                //else
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "")
                //    {
                //        TaskAPI["Step"]    = PreStep;
                //        TaskAPI["PreStep"] = "";
                //    }
                //    else
                //    {
                //        TaskAPI["Step"] = "";
                //        TaskAPI["PreStep"] = "";
                //    }
                //}
                //#endregion

                #endregion

                #region 提交步骤
                bool flg=false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        hsp_SpecialPrice hsp = new hsp_SpecialPrice();
                        if ((hsp_SpecialPrice.process == TaskAPI.Process & hsp_SpecialPrice.incident == TaskAPI.Incident & hsp_SpecialPrice.userName == UserAPI.UserName).Count<hsp_SpecialPrice>() > 0)
                        {
                            hsp = (hsp_SpecialPrice.process == TaskAPI.Process & hsp_SpecialPrice.incident == TaskAPI.Incident & hsp_SpecialPrice.userName == UserAPI.UserName).ListFirst<hsp_SpecialPrice>();
                        }
                        else
                        {
                            hsp.Process = TaskAPI.Process;
                            hsp.Incident = TaskAPI.Incident;
                            hsp.UserName = UserAPI.UserName;
                            hsp.UserFullName = UserAPI.UserFullName;
                            hsp.ApplicationNo = ApplicationNo.Text;
                            hsp.Time = System.DateTime.Now;
                            hsp.Status = 0;
                            hsp.Department = UserAPI.Department;
                        }

                        hsp.VD_Category       = VD_Category.SelectedValue;
                        hsp.DrpPriority = DrpPriority.SelectedValue;
                        hsp.VD_Checked        = VD.Checked ? "1" : "0";
                        hsp.SA_Checked        = SA.Checked ? "1" : "0";
                        hsp.SA2_Checked       = SA2.Checked ? "1" : "0";
                       
                      
                        #region VD
                        if (VD.Checked)
                        {
                            hsp.SpecialA_Condition_Type = SpecialA_Condition_Type.Text;
                            hsp.SpecialA_Sorg_DC = SpecialA_Sorg_DC.Checked ? "1" : "0";
                            hsp.SpecialA_Sales_Organization = SpecialA_Sales_Organization.Text;
                            hsp.Distribution_Channel = Distribution_Channel.Text;
                            hsp.SpecialA_Division = SpecialA_Division.SelectedValue;
                            hsp.SpecialA_Sold = SpecialA_Sold.Text;

                        }
                        #endregion

                        #region SA
                        if (SA.Checked)
                        {
                            hsp.SpecialB_Condition_Type = SpecialB_Condition_Type.Text;
                            hsp.SpecialB_Sorg_DC = SpecialB_Sorg_DC.Checked ? "1" : "0";
                            hsp.SpecialB_Sales_Organization = SpecialB_Sales_Organization.Text;
                            hsp.SpecialB_Channel = SpecialB_Channel.Text;
                            hsp.SpecialB_Division = SpecialB_Division.SelectedValue;

                        }
                        #endregion

                        #region SA2
                        if (SA2.Checked)
                        {
                            hsp.SpecialC_Condition_Type = SpecialC_Condition_Type.Text;
                            hsp.SpecialC_Sorg_DC = SpecialC_Sorg_DC.Checked ? "1" : "0";
                            hsp.SpecialC_Sales_Organization = SpecialC_Sales_Organization.Text;
                            hsp.SpecialC_Channel = SpecialC_Channel.Text;
                            hsp.SpecialC_Division = SpecialC_Division.SelectedValue;
                            hsp.SpecialC_Customer = SpecialC_Customer.Text;
                        }
                        #endregion

                    

                        
                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, hsp);
                    }
                    #endregion

                    Save();

                    #region Priority功能
                    if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = new mdc_Priority();
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = new mdc_Priority();
                            pro.Process = TaskAPI.Process;
                            pro.Incident = TaskAPI.Incident;
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }

                    }


                    if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check") && !string.IsNullOrEmpty(this.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {

                        //mdc_Priority pro;
                        //pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        //pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                        //Storage.Save(pro);
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }


                    }
                    #endregion

                    #region “DMO Maintain”步骤
                    if (TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check")
                    {

                        TaskAPI["DMO_DrpPriority"] = DMO_DrpPriority.SelectedItem.Text;
                        (hsp_SpecialPrice.process == TaskAPI.Process & hsp_SpecialPrice.incident == TaskAPI.Incident).Edit<hsp_SpecialPrice>(p =>
                        {
                            // p.SAP_Code = SAP_Code.Text;
                            p.DMO_DrpPriority = DMO_DrpPriority.SelectedValue;

                        }
                        );
                    }
                    #endregion

                    //#region “DMO Maintain”步骤
                    //if (TaskAPI.Step == "DMO Maintain")
                    //{
                    //    (hsp_SpecialPrice.process == TaskAPI.Process & hsp_SpecialPrice.incident == TaskAPI.Incident).Edit<hsp_SpecialPrice>(p =>
                    //    {
                    //        p.SAP_Code = SAP_Code.Text;
                    //    }    
                    //    );
                    //}
                    //#endregion

                    Storage.Save(Assessment1.Assessment);    //审批意见
                    
                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }

                    Assessment1.SubmitTo();

                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {
                    if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });
                    }
                    
                    (hsp_SpecialPrice.process == TaskAPI.Process & hsp_SpecialPrice.incident == 0 & hsp_SpecialPrice.userName == UserAPI.UserName).Edit<hsp_SpecialPrice>(p => 
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.userName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username== UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (hsp_SpecialPriceA_Gridview.process == TaskAPI.Process & hsp_SpecialPriceA_Gridview.incident == 0 & hsp_SpecialPriceA_Gridview.userName == UserAPI.UserName).Edit<hsp_SpecialPriceA_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (hsp_SpecialPriceB_Gridview.process == TaskAPI.Process & hsp_SpecialPriceB_Gridview.incident == 0 & hsp_SpecialPriceB_Gridview.userName == UserAPI.UserName).Edit<hsp_SpecialPriceB_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (hsp_SpecialPriceC_Gridview.process == TaskAPI.Process & hsp_SpecialPriceC_Gridview.incident == 0 & hsp_SpecialPriceC_Gridview.userName == UserAPI.UserName).Edit<hsp_SpecialPriceC_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (mdm_Sales_Gridview.process == TaskAPI.Process & mdm_Sales_Gridview.incident == 0 & mdm_Sales_Gridview.userName == UserAPI.UserName).Edit<mdm_Sales_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                    
                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

        #region 事件 CheckedChanged
        protected void VD_CheckedChanged(object sender, EventArgs e)
        {
            
            if (!VD.Checked && !SA.Checked && !SA2.Checked )
            {
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('至少保留一个选择项！',false)");
                VD.Checked = true;
            }
            SetVisible(false, P_VD, P_SA, P_SA2);

            switch(((Anthem.CheckBox)sender).ID)
            {
                case "VD":
                    
                    if (VD.Checked)
                    {
                       // SA.Checked = false;
                        //SA2.Checked = false;
                        //SA3.Checked = false;
                    }
                    //VD.Checked = !SA.Checked;
                    //VD.Checked = !SA2.Checked;
                    //VD.Checked = !SA3.Checked;
                    VD_L.Visible = VD.Checked;
                    break;
                
                case "SA":
                    if (SA.Checked)
                    {
                        //VD.Checked = false;
                        //SA2.Checked = false;
                        //SA3.Checked = false;
                    }
                    SA_L.Visible = SA.Checked;
                    //if (!SA.Checked & !SA2.Checked) SA.Checked = true;
                    //SA.Checked = !VD.Checked;
                    //SA.Checked = !SA2.Checked;
                    //SA.Checked = !SA3.Checked;
                    
                    //if (!SA.Checked & SA2.Checked) { SA2_L.CssClass = "tabs1"; Tabs_Click(SA2_L, e); }
                    break;

                case "SA2":

                    if (SA2.Checked)
                    {
                        //SA.Checked = false;
                        //VD.Checked = false;
                        //SA3.Checked = false;
                    }
                    //SA2.Checked = !SA.Checked;
                    //SA2.Checked = !VD.Checked;
                    //SA2.Checked = !SA3.Checked;
                    SA2_L.Visible = SA2.Checked;
                    break;

              
                    
            }
           
         
            InitTabs();
        }
        #endregion

        #region 事件 Category变换
        protected void VD_Category_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetEnable((VD_Category.SelectedValue == "1" || VD_Category.SelectedValue == "2" || VD_Category.SelectedValue == "3"), DrpPriority,SpecialA_Division, SpecialA_Sold, SpecialB_Division, SpecialC_Division, SpecialC_Customer);
            
        }
        #endregion

        #region 事件 Tabs切换
        protected void Tabs_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CssClass == "tabs2")
            {
                return;
            }

            #region 初始化
            SetVisible(false, P_VD, P_SA, P_SA2);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";
            #endregion

            #region Tabs切换动作
            switch (((LinkButton)sender).ID)
            {
                case "VD_L":
                    VD_L.CssClass = "tabs2";
                    P_VD.Visible = true;
                    break;
                case "SA_L":
                    SA_L.CssClass = "tabs2";
                    P_SA.Visible = true;
                    break;
                case "SA2_L":
                    SA2_L.CssClass = "tabs2";
                    P_SA2.Visible = true;
                    break;
            
            }
            #endregion
        }
        #endregion

        #region 方法 初始化Tabs
        protected void InitTabs()
        {
            VD_L.Visible = VD.Checked;
            SA_L.Visible = SA.Checked;
            SA2_L.Visible = SA2.Checked;
          
            SetVisible(false, P_VD, P_SA, P_SA2);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";
        

            //默认第1个显示 Tabs被选中
            if (VD_L.Visible)
            {
                VD_L.CssClass = "tabs2";
                P_VD.Visible = true;
                return;
            }

            if (SA_L.Visible)
            {
                SA_L.CssClass = "tabs2";
                P_SA.Visible = true;
                return;
            }

            if (SA2_L.Visible)
            {
                SA2_L.CssClass = "tabs2";
                P_SA2.Visible = true;
                return;
            }

       

        }
        #endregion

        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                
                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 Save(保存数据库)
        public void Save()
        {
            //if (!Status.IsEdited)
            //{
            //    return;
            //}

            foreach (hsp_SpecialPriceA_Gridview hsp_1 in (List<hsp_SpecialPriceA_Gridview>)gv_Special_A.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_1.SpecialA_Material) && string.IsNullOrEmpty(hsp_1.SpecialA_Status) && string.IsNullOrEmpty(hsp_1.SpecialA_Description) && string.IsNullOrEmpty(hsp_1.SpecialA_Proc) && string.IsNullOrEmpty(hsp_1.SpecialA_Calculat_Type) && string.IsNullOrEmpty(hsp_1.SpecialA_ScaleBasis))
                {
                    continue;
                }
                hsp_1.Process = TaskAPI.Process;
                hsp_1.Incident = TaskAPI.Incident;
                hsp_1.UserName = UserAPI.UserName;
                hsp_1.Time = System.DateTime.Now;
                hsp_1.Status = 0;
                Storage.Save(hsp_1);
            }

            foreach (hsp_SpecialPriceB_Gridview hsp_2 in (List<hsp_SpecialPriceB_Gridview>)gv_Special_B.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_2.SpecialB_Material) && string.IsNullOrEmpty(hsp_2.SpecialB_Description) && string.IsNullOrEmpty(hsp_2.SpecialB_Calculat_Type) && string.IsNullOrEmpty(hsp_2.SpecialB_ScaleBasis))
                {
                    continue;
                }
                hsp_2.Process = TaskAPI.Process;
                hsp_2.Incident = TaskAPI.Incident;
                hsp_2.UserName = UserAPI.UserName;
                hsp_2.Time = System.DateTime.Now;
                hsp_2.Status = 0;
                Storage.Save(hsp_2);
            }

            foreach (hsp_SpecialPriceC_Gridview hsp_3 in (List<hsp_SpecialPriceC_Gridview>)gv_Special_C.DataSource)
            {
                if (string.IsNullOrEmpty(hsp_3.SpecialC_Subgroup) && string.IsNullOrEmpty(hsp_3.SpecialC_Group) && string.IsNullOrEmpty(hsp_3.SpecialC_PH4) && string.IsNullOrEmpty(hsp_3.SpecialC_Description) && string.IsNullOrEmpty(hsp_3.SpecialC_Calculat_Type) && string.IsNullOrEmpty(hsp_3.SpecialC_ScaleBasis))
                {
                    continue;
                }
                hsp_3.Process = TaskAPI.Process;
                hsp_3.Incident = TaskAPI.Incident;
                hsp_3.UserName = UserAPI.UserName;
                hsp_3.Time = System.DateTime.Now;
                hsp_3.Status = 0;
                Storage.Save(hsp_3);
            }


        }
                    //TaskAPI["Material"] = SEFI_Material;


          #endregion

        #region 事件 Add(增加行)
        protected void Add_Click(object sender, EventArgs e)
        {
            switch (((Anthem.Button)sender).ID)
            {
                case "Special_A_Add":
                    List<hsp_SpecialPriceA_Gridview> special_1_s = (List<hsp_SpecialPriceA_Gridview>)gv_Special_A.DataSource;
                    hsp_SpecialPriceA_Gridview special_1 = new hsp_SpecialPriceA_Gridview();
                    special_1.No = special_1_s.Count + 1;
                    special_1_s.Insert(special_1_s.Count, special_1);
                    gv_Special_A.DataSource = special_1_s;
                    gv_Special_A.DataBind();
                    break;

                case "Special_B_Add":
                    List<hsp_SpecialPriceB_Gridview> special_2_s = (List<hsp_SpecialPriceB_Gridview>)gv_Special_B.DataSource;
                    hsp_SpecialPriceB_Gridview special_2 = new hsp_SpecialPriceB_Gridview();
                    special_2.No = special_2_s.Count + 1;
                    special_2_s.Insert(special_2_s.Count, special_2);
                    gv_Special_B.DataSource = special_2_s;
                    gv_Special_B.DataBind();
                    break;

                case "Special_C_Add":
                    List<hsp_SpecialPriceC_Gridview> special_3_s = (List<hsp_SpecialPriceC_Gridview>)gv_Special_C.DataSource;
                    hsp_SpecialPriceC_Gridview special_3 = new hsp_SpecialPriceC_Gridview();
                    special_3.No = special_3_s.Count + 1;
                    special_3_s.Insert(special_3_s.Count, special_3);
                    gv_Special_C.DataSource = special_3_s;
                    gv_Special_C.DataBind();
                    break;
            }
        }
        #endregion

        #region 事件 Delete(删除行)
        protected void Delete_Click(object sender, EventArgs e)
        {
            switch (((Anthem.Button)sender).ID)
            {
                case "Special_A_Delete":
                    //List<hsp_SpecialPriceA_Gridview> special_1_s = (List<hsp_SpecialPriceA_Gridview>)gv_Special_A.DataSource;
                    //if (special_1_s.Count == 1)
                    //{
                    //    return;
                    //}
                    //special_1_s.RemoveAt(gv_Special_A.ChangedRowIndex == -1 || gv_Special_A.ChangedRowIndex >= special_1_s.Count ? special_1_s.Count - 1 : gv_Special_A.ChangedRowIndex);
                    //gv_Special_A.DataSource = special_1_s;
                    //gv_Special_A.DataBind();
                    //break;

                    List<hsp_SpecialPriceA_Gridview> special_1_s = (List<hsp_SpecialPriceA_Gridview>)gv_Special_A.DataSource;
                    IList<hsp_SpecialPriceA_Gridview> Special1 = (hsp_SpecialPriceA_Gridview.process == TaskAPI.Process & hsp_SpecialPriceA_Gridview.incident == TaskAPI.Incident).List<hsp_SpecialPriceA_Gridview>();
                    if (special_1_s.Count == 1)
                    {

                        return;
                    }
                    special_1_s.RemoveAt(gv_Special_A.ChangedRowIndex == -1 || gv_Special_A.ChangedRowIndex >= special_1_s.Count ? special_1_s.Count - 1 : gv_Special_A.ChangedRowIndex);
                    bool flag = false;
                    foreach (hsp_SpecialPriceA_Gridview special_1 in Special1)
                    {

                        foreach (hsp_SpecialPriceA_Gridview special_2 in special_1_s)
                        {
                            if (special_2.ID == special_1.ID)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            Storage.Delete(special_1);
                        }
                        flag = false;
                    }
                    gv_Special_A.DataSource = special_1_s;
                    gv_Special_A.DataBind();
                    break;

                case "Special_B_Delete":
                    //List<hsp_SpecialPriceB_Gridview> special_2_s = (List<hsp_SpecialPriceB_Gridview>)gv_Special_B.DataSource;
                    //if (special_2_s.Count == 1)
                    //{
                    //    return;
                    //}
                    //special_2_s.RemoveAt(gv_Special_B.ChangedRowIndex == -1 || gv_Special_B.ChangedRowIndex >= special_2_s.Count ? special_2_s.Count - 1 : gv_Special_B.ChangedRowIndex);
                    //gv_Special_B.DataSource = special_2_s;
                    //gv_Special_B.DataBind();
                    //break;

                    List<hsp_SpecialPriceB_Gridview> special_2_s = (List<hsp_SpecialPriceB_Gridview>)gv_Special_B.DataSource;
                    IList<hsp_SpecialPriceB_Gridview> special2 = (hsp_SpecialPriceB_Gridview.process == TaskAPI.Process & hsp_SpecialPriceB_Gridview.incident == TaskAPI.Incident).List<hsp_SpecialPriceB_Gridview>();
                    if (special_2_s.Count == 1)
                    {

                        return;
                    }
                    special_2_s.RemoveAt(gv_Special_B.ChangedRowIndex == -1 || gv_Special_B.ChangedRowIndex >= special_2_s.Count ? special_2_s.Count - 1 : gv_Special_B.ChangedRowIndex);
                    bool flag1 = false;
                    foreach (hsp_SpecialPriceB_Gridview special_2 in special2)
                    {

                        foreach (hsp_SpecialPriceB_Gridview special_22 in special_2_s)
                        {
                            if (special_22.ID == special_2.ID)
                            {
                                flag1 = true;
                                break;
                            }
                        }
                        if (!flag1)
                        {
                            Storage.Delete(special_2);
                        }
                        flag1 = false;
                    }
                    gv_Special_B.DataSource = special_2_s;
                    gv_Special_B.DataBind();
                    break;


                case "Special_C_Delete":
                    //List<hsp_SpecialPriceC_Gridview> special_3_s = (List<hsp_SpecialPriceC_Gridview>)gv_Special_C.DataSource;
                    //if (special_3_s.Count == 1)
                    //{
                    //    return;
                    //}
                    //special_3_s.RemoveAt(gv_Special_C.ChangedRowIndex == -1 || gv_Special_C.ChangedRowIndex >= special_3_s.Count ? special_3_s.Count - 1 : gv_Special_C.ChangedRowIndex);
                    //gv_Special_C.DataSource = special_3_s;
                    //gv_Special_C.DataBind();
                    //break;

                    List<hsp_SpecialPriceC_Gridview> base_1_s = (List<hsp_SpecialPriceC_Gridview>)gv_Special_C.DataSource;
                    IList<hsp_SpecialPriceC_Gridview> base1 = (hsp_SpecialPriceC_Gridview.process == TaskAPI.Process & hsp_SpecialPriceC_Gridview.incident == TaskAPI.Incident).List<hsp_SpecialPriceC_Gridview>();
                    if (base_1_s.Count == 1)
                    {

                        return;
                    }
                    base_1_s.RemoveAt(gv_Special_C.ChangedRowIndex == -1 || gv_Special_C.ChangedRowIndex >= base_1_s.Count ? base_1_s.Count - 1 : gv_Special_C.ChangedRowIndex);
                    bool flag2 = false;
                    foreach (hsp_SpecialPriceC_Gridview base_1 in base1)
                    {

                        foreach (hsp_SpecialPriceC_Gridview base_2 in base_1_s)
                        {
                            if (base_2.ID == base_1.ID)
                            {
                                flag2 = true;
                                break;
                            }
                        }
                        if (!flag2)
                        {
                            Storage.Delete(base_1);
                        }
                        flag2 = false;
                    }
                    gv_Special_C.DataSource = base_1_s;
                    gv_Special_C.DataBind();
                    break;
            }
        }
        #endregion

        #region 方法 数据验证
        private List<string> DataValidation()
        {
            #region VD
            List<Regular> regs = new List<Regular>();
            //if (VD.Checked && SA.Checked ) { regs.Add(new Regular(RegularExp.NotEmpty, "", "material: 选择了Employee 则不能选material")); }
            if (VD.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SpecialA_Division.SelectedValue, " Special Price A: Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SpecialA_Sold.Text, " Special Price A: Sold-to party 必填"));

                foreach (hsp_SpecialPriceA_Gridview SPA in (List<hsp_SpecialPriceA_Gridview>)gv_Special_A.DataSource)
                {
                    if (string.IsNullOrEmpty(SPA.SpecialA_Material) && string.IsNullOrEmpty(SPA.SpecialA_Amount) && string.IsNullOrEmpty(SPA.SpecialA_Unit) && string.IsNullOrEmpty(SPA.SpecialA_Valid_From) && string.IsNullOrEmpty(SPA.SpecialA_Valid_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(SPA.SpecialA_Material))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPA.SpecialA_Material, "&nbsp;&nbsp;行" + SPA.No + ": Special Price A: Material 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPA.SpecialA_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPA.SpecialA_Amount, "&nbsp;&nbsp;行" + SPA.No + ": Special Price A: Amount 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPA.SpecialA_Unit))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPA.SpecialA_Unit, "&nbsp;&nbsp;行" + SPA.No + ": Special Price A: Unit 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPA.SpecialA_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPA.SpecialA_Valid_From, "&nbsp;&nbsp;行" + SPA.No + ": Special Price A: Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPA.SpecialA_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPA.SpecialA_Valid_To, "&nbsp;&nbsp;行" + SPA.No + ": Special Price A: Valid To 为必填 "));
                    }
                }
            }
            #endregion

            #region SA
            if (SA.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SpecialB_Division.SelectedValue, " Special Price B: Division 必填"));


                foreach (hsp_SpecialPriceB_Gridview SPB in (List<hsp_SpecialPriceB_Gridview>)gv_Special_B.DataSource)
                {
                    if (string.IsNullOrEmpty(SPB.SpecialB_Material) && string.IsNullOrEmpty(SPB.SpecialB_Amount) && string.IsNullOrEmpty(SPB.SpecialB_Unit) && string.IsNullOrEmpty(SPB.SpecialB_Valid_From) && string.IsNullOrEmpty(SPB.SpecialB_Valid_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(SPB.SpecialB_Material))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.SpecialB_Material, "&nbsp;&nbsp;行" + SPB.No + ": Special Price B: Material 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPB.SpecialB_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.SpecialB_Amount, "&nbsp;&nbsp;行" + SPB.No + ": Special Price B: Amount 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPB.SpecialB_Unit))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.SpecialB_Unit, "&nbsp;&nbsp;行" + SPB.No + ": Special Price B: Unit 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPB.SpecialB_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.SpecialB_Valid_From, "&nbsp;&nbsp;行" + SPB.No + ": Special Price B: Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPB.SpecialB_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPB.SpecialB_Valid_To, "&nbsp;&nbsp;行" + SPB.No + ": Special Price B: Valid To 为必填 "));
                    }

                }

            }
            #endregion

            #region SA2
            if (SA2.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SpecialC_Division.SelectedValue, " Special Price C: Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SpecialC_Division.SelectedValue, " Special Price C: Customer 必填"));
                
                foreach (hsp_SpecialPriceC_Gridview SPC in (List<hsp_SpecialPriceC_Gridview>)gv_Special_C.DataSource)
                {

                    if (string.IsNullOrEmpty(SPC.SpecialC_Subgroup) && string.IsNullOrEmpty(SPC.SpecialC_Tin) && string.IsNullOrEmpty(SPC.SpecialC_Amount) && string.IsNullOrEmpty(SPC.SpecialC_Unit) && string.IsNullOrEmpty(SPC.SpecialC_Valid_From) && string.IsNullOrEmpty(SPC.SpecialC_Valid_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(SPC.SpecialC_Subgroup))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.SpecialC_Subgroup, "&nbsp;&nbsp;行" + SPC.No + ": Special Price C: Subgroup 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPC.SpecialC_Tin))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.SpecialC_Tin, "&nbsp;&nbsp;行" + SPC.No + ": Special Price C: Tin size 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPC.SpecialC_Amount))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.SpecialC_Amount, "&nbsp;&nbsp;行" + SPC.No + ": Special Price C: Amount 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPC.SpecialC_Unit))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.SpecialC_Unit, "&nbsp;&nbsp;行" + SPC.No + ": Special Price C: Unit 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPC.SpecialC_Valid_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.SpecialC_Valid_From, "&nbsp;&nbsp;行" + SPC.No + ": Special Price C: Valid From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(SPC.SpecialC_Valid_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, SPC.SpecialC_Valid_To, "&nbsp;&nbsp;行" + SPC.No + ": Special Price C: Valid To 为必填 "));
                    }

                }
            }
            #endregion

            return Validation(regs);
        }
        #endregion

        #region 方法 Others
        protected void VD_Payment_Methods_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }
        private string getFormCheckList(Anthem .CheckBoxList ck)
        {
            string t = "";
            for (int i = 0; i < ck.Items.Count; i++)
                if (ck.Items[i].Selected)
                    t += "," + ck.Items[i].Value;
                else
                    t += ",";
            return t;
        }
        private Anthem.CheckBoxList setCheckList(string t, Anthem .CheckBoxList ck)
        {
            try
            {
                string[] tt = t.Split(',');

                for (int i = 0; i <= tt.GetUpperBound(0); i++)
                {
                    for (int j = 0; j < ck.Items.Count; j++)
                    {
                        if (ck.Items[j].Value == tt[i].ToString())
                        { ck.Items[j].Selected = true; break; }
                    }
                }
            }
            catch { }
            return ck;
        }
        #endregion

        

       
    }
}